package logic

import (
	"Junior_two/subject/usercenter/userrpc/internal/dao"
	"context"
	"encoding/json"

	"Junior_two/subject/usercenter/userrpc/internal/svc"
	"Junior_two/subject/usercenter/userrpc/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
	return &UserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserInfoLogic) UserInfo(in *user.UserRequest) (*user.UserResponse, error) {
	// todo: add your logic here and delete this line
	u := dao.UserInfo(in.Username)
	jsU, _ := json.Marshal(u)
	return &user.UserResponse{
		Id:       u.Id,
		Username: u.Username,
		Data:     string(jsU),
	}, nil
}
